home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Surfer: Getting Started
/
Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin
/
pc
/
mac
/
bonus
/
peter_le
/
finger-1
/
my_units
/
mynotifi.uni
< prev
next >
Wrap
Text File
|
1992-02-24
|
5KB
|
213 lines
unit MyNotifier;
{ This code is part of the Finger/Fingerd source code, written in THINK Pascal 4 }
{ Copyright 1991-1992 Peter N Lewis }
{ This code is public domain. Do with it as you like }
{ This is from my library of useful routines }
{ Derived from <jholt@adobe.COM> Joe Holt's StartupError code as posted }
{ to comp.sys.mac.programmer in May 1991 }
{ Notification Manager messages }
{ History: }
{ jhh 18 jun 90 -- response to news posting }
{ pnl 29 may 91 -- Converted to pascal to be used in an application }
interface
const
mark_app = 1;
mark_none = 0;
procedure InitNotify;
procedure FinishNotify;
procedure NotifyH (mark: integer; sound: handle; sicn: handle; str: stringPtr);
procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
{ mark - mark the current application }
{ sound - play sysbeep }
{ sicn_id, sicn_index - SICN id to rotate with the apple & index (<1 -> 1) OR 0&0 for no sicn }
{ str_id, str_index - STR# id & index OR STR id & 0 OR 0 & 0 }
procedure NotifyCompletion;
{ Call this when in event loop when in the foreground to remove apple mark and flash }
procedure UnNotify;
{ Call this to get rid of the notification }
var
notify_finished: boolean;
implementation
uses
Notification;
const
sicn_size = 32;
T_NMInstall = $A05E;
T_Unimplemented = $A89F;
type
NMRecPtrPtr = ^NMRecPtr;
booleanPtr = ^boolean;
var
current_note: NMRecPtr;
{ handles must be non-purgeable, but may be unlocked }
{$S Init}
procedure InitNotify;
begin
current_note := nil;
notify_finished := false;
end;
{$S}
procedure MyResponse (note: NMRecPtr);
begin
booleanPtr(note^.nmRefCon)^ := true;
end;
{$S Util}
procedure UnNotify;
var
oe: OSErr;
begin
if current_note <> nil then begin
oe := NMRemove(current_note);
with current_note^ do begin
if nmStr <> nil then
DisposPtr(pointer(nmStr));
if nmIcon <> nil then
DisposHandle(nmIcon);
end;
DisposPtr(pointer(current_note));
current_note := nil;
end;
notify_finished := false;
end;
{$S}
procedure NotifyCompletion;
begin
if notify_finished then
UnNotify;
end;
{$S Term}
procedure FinishNotify;
begin
if current_note <> nil then
UnNotify;
end;
{$S Util}
procedure NotifyH (mark: integer; sound: handle; sicn: handle; str: stringPtr);
var
errorText: str255;
sh: stringHandle;
sicnH: handle;
error: boolean;
oe: OSErr;
begin
UnNotify; { Clear outstanding notify }
if NGetTrapAddress(T_NMInstall, OSTrap) = NGetTrapAddress(T_Unimplemented, ToolTrap) then begin
SysBeep(1); { Best we can do I guess. Could put up the dialog box maybe?...}
end
else begin
current_note := NMRecPtr(NewPtr(sizeof(NMRec)));
if current_note = nil then begin
SysBeep(1); { Can't do much else if there isnt even room for this! }
end
else begin
with current_note^ do begin
qType := nmType;
error := false;
booleanPtr(nmRefCon) := @notify_finished;
nmMark := mark;
nmStr := str;
nmIcon := sicn;
nmSound := sound;
nmResp := @MyResponse;
end;
oe := NMInstall(current_note);
if oe <> noErr then begin
current_note := nil;
SysBeep(1);
end;
end;
end;
end;
{$S Util}
procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
var
errorText: str255;
sh: stringHandle;
sicnH: handle;
error: boolean;
oe: OSErr;
nmMark: integer;
nmStr: stringPtr;
nmIcon: handle;
nmSound: handle;
begin
error := false;
if mark then
nmMark := 1
else
nmMark := 0;
nmStr := nil;
if str_id <> 0 then begin
if str_index > 0 then
GetIndString(errorText, str_id, str_index)
else begin
errorText := '';
sh := GetString(str_id);
if sh <> nil then begin
if sh^ <> nil then
errorText := sh^^;
ReleaseResource(handle(sh));
end;
end;
if errorText = '' then
error := true
else begin
nmStr := stringPtr(NewPtr(length(errorText) + 1));
if nmStr = nil then
error := true
else
nmStr^ := errorText;
end;
end;
nmIcon := nil;
if sicn_id <> 0 then begin
if sicn_index < 1 then
sicn_index := 1;
sicn_index := (sicn_index - 1) * sicn_size; { 1-based, like STR# }
sicnH := GetResource('SICN', sicn_id);
HNoPurge(sicnH);
if sicnH = nil then
error := true
else begin
nmIcon := NewHandle(sicn_size);
if nmIcon = nil then
error := true
else if nmIcon^ = nil then
error := true
else if GetHandleSize(sicnH) < sicn_index + sicn_size then
error := true
else begin
BlockMove(ptr(longInt(sicnH^) + sicn_index), nmIcon^, sicn_size);
end;
ReleaseResource(sicnH);
end;
end;
if sound or error then
nmSound := handle(-1)
else
nmSound := nil;
NotifyH(nmMark, nmSound, nmIcon, nmStr);
end;
end.